package com.financial.business.yspay.service.impl;

import com.financial.business.yspay.constants.YsBusinessEnumConstants;
import com.financial.business.yspay.service.*;
import com.financial.business.yspay.service.query.*;
import com.financial.business.yspay.utils.JsonUtils;
import com.financial.business.yspay.utils.apiresult.ApiResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author WANGNING
 * @email wyn20140226@aliyun.com
 * @date 2019/11/5 9:25
 * @apiGroup ys-business
 * @apiVersion 2.0.0
 */
@Service
public class YsBusinessServiceImpl implements YsBusinessService {
    public static final Logger logger = LoggerFactory.getLogger(YsBusinessServiceImpl.class);
    @Autowired
    private FinancialPayYsService financialPayYsService;

    @Autowired
    private FinancialSplitYsService financialSplitYsService;

    @Autowired
    private FinancialWithdrawalYsService financialWithdrawalYsService;

    @Autowired
    private FinancialPaymentYsService financialPaymentYsService;

    @Autowired
    private FinancialReportYsService financialReportYsService;

    @Autowired
    private FinancialRefundYsService financialRefundYsService;
    /*-------查询接口服务------*/
    @Autowired
    private FinancialQueryBalanceService financialQueryBalanceService;

    @Autowired
    private FinancialQueryPayService financialQueryPayService;

    @Autowired
    private FinancialQueryPaymentService financialQueryPaymentService;

    @Autowired
    private FinancialQuerySplitService financialQuerySplitService;

    @Autowired
    private FinancialQueryWithdrawalService financialQueryWithdrawalService;

    @Autowired
    private FinancialQueryReportService financialQueryReportService;

    @Autowired
    private FinancialQueryRefundService financialQueryRefundService;

    @Override
    public ApiResult report(String requestParam) {
        /*银盛支付报备处理*/
        Map<String, Object> condMap = JsonUtils.jsonToMap(requestParam);
        String reportType = (String) condMap.get("report_type");
        logger.info("YsBusinessServiceImpl.pay()----金融中心银盛基类，获取报备类型：" + reportType);
        ApiResult apiResult = ApiResult.failure(YsBusinessEnumConstants.ENUM_REPORTTYPE_ERROR);
        if (reportType.equalsIgnoreCase(YsBusinessEnumConstants.ENUM_REPORTTYPE_REGISTER)) {
            /*银盛报备*/
            apiResult = financialReportYsService.ysReport(requestParam);
        }
        return apiResult;
    }

    @Override
    public ApiResult pay(String requestParam) {
        /*银盛支付业务处理---判断是哪种支付渠道*/
        Map<String, Object> condMap = JsonUtils.jsonToMap(requestParam);
        String payType = (String) condMap.get("pay_type");
        logger.info("YsBusinessServiceImpl.pay()----金融中心银盛基类，获取支付类型：" + payType);
        ApiResult apiResult = ApiResult.failure(YsBusinessEnumConstants.ENUM_PAYTYPE_ERROR);
        if (payType.equalsIgnoreCase(YsBusinessEnumConstants.ENUM_PAYTYPE_WECHAT)) {
            /*微信支付*/
            apiResult = financialPayYsService.ysWeChatPay(requestParam);
        } else if (payType.equalsIgnoreCase(YsBusinessEnumConstants.ENUM_PAYTYPE_ALI)) {
            /*支付宝支付*/
            apiResult = financialPayYsService.ysAliPay(requestParam);
        }
        return apiResult;
    }

    @Override
    public ApiResult split(String requestParam) {
        /*银盛结算分账业务处理 ---银盛一清分账*/
        Map<String, Object> condMap = JsonUtils.jsonToMap(requestParam);
        String splitType = (String) condMap.get("split_type");
        logger.info("YsBusinessServiceImpl.split()----金融中心银盛基类，获取分账类型：" + splitType);
        ApiResult apiResult = ApiResult.failure(YsBusinessEnumConstants.ENUM_SPLITTYPE_ERROR);
        if (splitType.equalsIgnoreCase(YsBusinessEnumConstants.ENUM_SPLITTYPE_FIRSTCLEAR)) {
            /*银盛一清分账*/
            apiResult = financialSplitYsService.ysSplit(requestParam);
        } else {
            /*银盛其他报备*/
        }
        return apiResult;
    }

    @Override
    public ApiResult refund(String requestParam) {
        /*银盛结算退款业务处理 ---银盛一清退款*/
        Map<String, Object> condMap = JsonUtils.jsonToMap(requestParam);
        String refundType = (String) condMap.get("refund_type");
        logger.info("YsBusinessServiceImpl.refund()----金融中心银盛基类，获取退款类型：" + refundType);
        ApiResult apiResult = ApiResult.failure(YsBusinessEnumConstants.ENUM_REFUNDTYPE_ERROR);
        if (refundType.equalsIgnoreCase(YsBusinessEnumConstants.ENUM_REFUNDTYPE_FIRSTCLEAR)) {
            /*银盛一清退款*/
            apiResult = financialRefundYsService.ysRefund(requestParam);
        } else {
            /*银盛其他退款*/
        }
        return apiResult;
    }

    @Override
    public ApiResult withdrawal(String requestParam) {
        /*银盛结算提现业务处理 ---银盛一清提现*/
        Map<String, Object> condMap = JsonUtils.jsonToMap(requestParam);
        String withdrawalType = (String) condMap.get("withdrawal_type");
        logger.info("YsBusinessServiceImpl.withdrawal()----金融中心银盛基类，获取提现类型：" + withdrawalType);
        ApiResult apiResult = ApiResult.failure(YsBusinessEnumConstants.ENUM_WITHDRAWALTYPE_ERROR);
        if (withdrawalType.equalsIgnoreCase(YsBusinessEnumConstants.ENUM_WITHDRAWALTYPE_FIRSTCLEAR)) {
            /*银盛一清提现*/
            apiResult = financialWithdrawalYsService.ysWithdrawal(requestParam);
        } else {
            /*银盛其他提现*/
        }
        return apiResult;
    }

    @Override
    public ApiResult payment(String requestParam) {
        /*银盛代付/转账业务处理*/
        Map<String, Object> condMap = JsonUtils.jsonToMap(requestParam);
        String paymentType = (String) condMap.get("payment_type");
        logger.info("YsBusinessServiceImpl.withdrawal()----金融中心银盛基类，获取代付类型：" + paymentType);
        ApiResult apiResult = ApiResult.failure(YsBusinessEnumConstants.ENUM_PAYMENTYPE_ERROR);
        if (paymentType.equalsIgnoreCase(YsBusinessEnumConstants.ENUM_PAYMENT_FIRSTCLEAR)) {
            /*银盛一清代付*/
            apiResult = financialPaymentYsService.ysPayment(requestParam);
        } else {
            /*银盛其他代付*/
        }
        return apiResult;
    }

    @Override
    public ApiResult query(String requestParam) {
        /*银盛查询*/
        Map<String, Object> condMap = JsonUtils.jsonToMap(requestParam);
        String queryType = (String) condMap.get("query_type");
        logger.info("YsBusinessServiceImpl.query()----金融中心银盛基类，获查询付类型：" + queryType);
        ApiResult apiResult = ApiResult.failure(YsBusinessEnumConstants.ENUM_QUERYTYPE_ERROR);
        if (queryType.equalsIgnoreCase(YsBusinessEnumConstants.ENUM_QUERYTYPE_REPORT)) {
            /*报备*/
            apiResult = financialQueryReportService.reportQuery(requestParam);
        } else if (queryType.equalsIgnoreCase(YsBusinessEnumConstants.ENUM_QUERYTYPE_PAY)) {
            /*支付*/
            apiResult = financialQueryPayService.payQuery(requestParam);
        } else if (queryType.equalsIgnoreCase(YsBusinessEnumConstants.ENUM_QUERYTYPE_SPLIT)) {
            /*分账*/
            apiResult = financialQuerySplitService.splitQuery(requestParam);
        } else if (queryType.equalsIgnoreCase(YsBusinessEnumConstants.ENUM_QUERYTYPE_WITHDRAWAL)) {
            /*提现*/
            apiResult = financialQueryWithdrawalService.withdrawalQuery(requestParam);
        } else if (queryType.equalsIgnoreCase(YsBusinessEnumConstants.ENUM_QUERYTYPE_PAYMENT)) {
            /*代付*/
            apiResult = financialQueryPaymentService.paymentQuery(requestParam);
        } else if (queryType.equalsIgnoreCase(YsBusinessEnumConstants.ENUM_QUERYTYPE_BALANCE)) {
            /*余额查询*/
            apiResult = financialQueryBalanceService.balanceQuery(requestParam);
        } else if(queryType.equalsIgnoreCase(YsBusinessEnumConstants.ENUM_QUERYTYPE_REFUND)){
            /*退款查询*/
            apiResult = financialQueryRefundService.refundQuery(requestParam);
        } else {
            /*银盛其他查询*/
        }
        return apiResult;
    }
}
